Page({
  data: {
    userInfo: {
      name: '张三',
      id: '138****8888',
      avatarUrl: '',
      memberLevel: '普通会员',
      upgradeAmount: 1000,
      progressPercent: 33
    },
    menuList: [
      { icon: 'ri-file-list-line', name: '我的订单', path: '/pages/my-orders/my-orders' },
      { icon: 'ri-shield-check-line', name: '实名认证', path: '/pages/verify/verify' },
      { icon: 'ri-customer-service-line', name: '联系客服', action: 'contactService' },
      { icon: 'ri-question-line', name: '帮助中心', path: '/pages/help/help' },
      { icon: 'ri-settings-3-line', name: '设置', path: '/pages/settings/settings' }
    ],
    functionMenus: [
      { icon: 'ri-time-line', name: '待取车', status: 'pending', count: 1 },
      { icon: 'ri-car-line', name: '使用中', status: 'using', count: 1 },
      { icon: 'ri-check-line', name: '已完成', status: 'completed', count: 2 },
      { icon: 'ri-history-line', name: '浏览记录', status: 'history', count: 0 }
    ]
  },
  onLoad() {
    console.log('个人中心页加载');
    // 获取用户信息
    this.getUserInfo();
  },
  getUserInfo() {
    // 实际应用中应该从服务器获取用户信息
    console.log('获取用户信息');
  },
  goToSettings() {
    wx.navigateTo({
      url: '/pages/settings/settings'
    });
  },
  navigateTo(e) {
    const index = e.currentTarget.dataset.index;
    const item = this.data.menuList[index];
    
    if (item.action) {
      this[item.action]();
    } else if (item.path) {
      wx.navigateTo({
        url: item.path
      });
    }
  },
  goToOrderStatus(e) {
    const index = e.currentTarget.dataset.index;
    const item = this.data.functionMenus[index];
    const status = item.status;
    
    wx.navigateTo({
      url: `/pages/my-orders/my-orders?status=${status}`
    });
  },
  contactService() {
    wx.makePhoneCall({
      phoneNumber: '400-123-4567'
    });
  },
  logout() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          // 清除登录状态
          wx.removeStorageSync('token');
          wx.removeStorageSync('userInfo');
          
          // 跳转到登录页
          wx.navigateTo({
            url: '/pages/login/login'
          });
        }
      }
    });
  }
}); 
